package com.woniuxy.service.impl;





import com.woniuxy.dao.UserDao;
import com.woniuxy.entity.User;
import com.woniuxy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("userService")
public class UserServiceImpl implements UserService {
	@Autowired
	@Qualifier("userDao")
	private UserDao userDao;




	//根据账号查找用户
	@Override
	public User findByAccount(String account, String password) {
		User user = userDao.findByAccount(account);

		if(user == null) {
			throw new RuntimeException("账户不存在");
		}
		if(!user.getPassword().equals(password)) {
			throw new RuntimeException("密码错误");
		}
		if(user.getStatus().equals("0")) {
			throw new RuntimeException("请先去激活");
		}
		return user;
	}


	//账户是否存在
	@Override
	public User findAccount(String account) {

		return userDao.findByAccount(account);
	}

//	//注册用户
	@Transactional
	@Override
	public boolean addUser(User user) {

		return userDao.insertUser(user) > 0;

	}

	//根据邮箱查找
	@Override
	public User findByEmail(String email) {

		return userDao.findByEmail(email);
	}



	
}
